import { DataSet } from 'choerodon-ui/pro';
import JSONbig from 'json-bigint';
import { DataSetSelection, FieldType } from '@/interface';

export default (
  {
    formatMessage,
    intlPrefix,
    projectId,
  }:
  {
   formatMessage:Function,
   intlPrefix:string,
   projectId:string
  },
) => ({
  autoQuery: true,
  autoCreate: true,
  selection: false as any,
  paging: true,
  pageSize: 10,
  queryFields: [
    {
      name: 'param',
      type: 'string' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.name` }),
    },
    {
      name: 'status',
      type: 'string'as FieldType,
      textFiled: 'meaning',
      valueField: 'value',
      label: formatMessage({ id: `${intlPrefix}.runStatus` }),
      options: new DataSet({
        selection: 'single' as DataSetSelection,
        data: [
          {
            meaning: '已跳过',
            value: 'skipped',
          },
          {
            meaning: '未执行',
            value: 'created',
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.runStatus.prepare` }),
            value: 'pending',
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.runStatus.run` }),
            value: 'running',
          },
          {
            meaning: '已取消',
            value: 'canceled',
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.runStatus.check` }),
            value: 'not_audit',
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.runStatus.success` }),
            value: 'success',
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.runStatus.failed` }),
            value: 'failed',
          },
          {
            meaning: '已终止',
            value: 'stop',
          },
        ],
      }),
    },
    {
      name: 'trigger_type',
      type: 'string' as FieldType,
      textFiled: 'text',
      valueField: 'value',
      label: formatMessage({ id: `${intlPrefix}.triggerType` }),
      options: new DataSet({
        selection: 'single' as DataSetSelection,
        data: [
          {
            meaning: '手动触发',
            value: 'manual',
          },
          {
            meaning: '定时触发',
            value: 'schedule',
          },
          {
            meaning: '应用服务版本触发',
            value: 'app_version',
          },
          {
            meaning: 'api触发',
            value: 'api',
          },
        ],
      }),
    },
    {
      name: 'enable',
      type: 'boolean' as FieldType,
      textFiled: 'text',
      valueField: 'value',
      label: formatMessage({ id: `${intlPrefix}.status` }),
      options: new DataSet({
        selection: 'single' as DataSetSelection,
        data: [
          {
            meaning: formatMessage({ id: `${intlPrefix}.status.able` }),
            value: true,
          },
          {
            meaning: formatMessage({ id: `${intlPrefix}.status.disabled` }),
            value: false,
          },
        ],
      }),
    },
  ],
  fields: [
    {
      name: 'id',
      type: 'string' as FieldType,
    },
    {
      name: 'name',
      type: 'string' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.name` }),
    },
    {
      name: 'status',
      type: 'string' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.runStatus` }),
    },
    {
      name: 'stageRecordList',
      type: 'object' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.runStage` }),
    },
    {
      name: 'trigger',
      type: 'object' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.triggerInfo` }),
    },
    {
      name: 'triggerType',
      type: 'string' as FieldType,
    },
    {
      name: 'staredDate',
      type: 'string' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.staredDates` }),
    },
    {
      name: 'enable',
      type: 'boolean' as FieldType,
      label: formatMessage({ id: `${intlPrefix}.status` }),
    },
  ],
  transport: {
    read: {
      url: `/devops/v1/projects/${projectId}/pipelines/paging`,
      method: 'get',
      transformResponse: (res:any) => {
        const newRes = JSONbig.parse(res);
        return newRes;
      },
    },
  },
  events: {

  },
});
